$(document).ready(function() {
	
	
	
	$('#itemCode').change(function() {
		$.getJSON('getCategory.do?itemName='+this.value,function(data) {
			//alert(data.str);
			var category=document.getElementById("category");
			
			category.value=data.str;
			
		});
	});
	
	if($("#mode").val() == 'I'){
		$("#delete").css("display","none");
		$("#modify").css("display","none");
		$("#filedown").css("display","none");
	}else if ($("#mode").val() == 'M') {
		$("form *").attr("disabled",true);
		$("#delete").attr("disabled",false);
		$("#modify").attr("disabled",false);
		$("#cancel").attr("disabled",false);
		$("#save").attr("disabled",false);
		$("#save").css("display","none");
	}else if ($("#mode").val() == 'V') {
		$("form *").attr("disabled",true);
		$("#delete").attr("disabled",false);
		$("#modify").attr("disabled",false);
		$("#cancel").attr("disabled",false);
		$("#save").attr("disabled",false);
		$("#save").css("display","none");
		$("#delete").css("display","none");
		$("#modify").css("display","none");
		
	}
});

function searchEmp() {
	window.open("doSearchEmpView.do","doSearchEmpView","height=300,width=300,left=200,top=200,modal=yes");
	//$("#dialog").dialog({modal:true});
}

function formValidate() {
	//검증
	var employeeName=document.getElementById("employeeName").value;
	var productCode=document.getElementById("productCode").value;
	var productName=document.getElementById("productName").value;
	var itemCode=document.getElementById("itemCode").value;
	var manufactureCode=document.getElementById("manufactureCode").value;
	var standard=document.getElementById("standard").value;
	var unitCode=document.getElementById("unitCode").value;
	var unitPrice=document.getElementById("unitPrice").value;
	
	if(employeeName == ''){
		alert("사원번호를 입력해주세요");
		return false;
	}
	if(productCode == ''){
		alert("상품코드를 입력세주세요");
		return false;
	}
	if(productName == ''){
		alert("상품명을 입력해주세요");
		return false;
	}
	if(itemCode == ''){
		alert("품목명을 입력해주세요");
		return false;
	}
	if(manufactureCode == ''){
		alert("제조사를 입력해주세요");
		return false;
	}
	if(standard == ''){
		alert("규격을 입력해주세요");
		return false;
	}
	if(unitCode == ''){
		alert("단위를 입력해주세요");
		return false;
	}
	if(unitPrice == ''){
		alert("단가를 입력해주세요");
		return false;
	}
	
	return true;
}
document.getElementById("save").addEventListener("click", function() {	
	var mode=document.getElementById("mode").value;
	var frm=document.forms[0];
	
	if(mode == 'I'){
		/*if(!formValidate()){
			return;
		}*/
		
		frm.action="insPDTInfo.do?mode=I";
			
	}else if(mode == 'M'){
		/*if(!formValidate()){
			return;
		}*/
		
		frm.action="setPDTInfo.do?mode=M";
		$("#productNum").attr("disabled",false);
	}
	
	$("#employeeName").attr("disabled",false);
	$("#name").attr("disabled",false);
	$("#dept_code").attr("disabled",false);
	$("#category").attr("disabled",false);
	$("#productNum").attr("disabled",false);
	
	frm.submit();
	
}, false);

document.getElementById("modify").addEventListener("click", function() {
	$("#save").css("display","inline");
	$("#delete").css("display","none");
	$("#modify").css("display","none");
	
	$("form *").attr("disabled",false);
	$("#employeeName").attr("disabled",true);
	$("#name").attr("disabled",true);
	$("#dept_code").attr("disabled",true);
	$("#category").attr("disabled",true);
	$("#productNum").attr("disabled",true);
}, false);

document.getElementById("delete").addEventListener("click", function() {
	var frm=document.forms[0];
	
	if(confirm("정말 삭제하겠습니까?")){
		$("#productNum").attr("disabled",false);
		frm.action="delPDTInfo.do";
		frm.submit();	
	}
	
}, false);
document.getElementById("cancel").addEventListener("click", function() {
	self.close();
}, false);

